package com.chx.three.mama.activities;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.widget.RadioGroup;

import com.chx.three.mama.R;
import com.chx.three.mama.fragments.ActionFragment;
import com.chx.three.mama.fragments.FindFragment;
import com.chx.three.mama.fragments.MineFragment;
import com.chx.three.mama.fragments.RingFragment;
import com.chx.three.mama.fragments.SocialFragment;
import com.chx.three.mama.utils.SPHelper;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

@ContentView(R.layout.activity_main)
public class MainActivity extends FragmentActivity {
    @ViewInject(R.id.main_tab_check)
    RadioGroup mCheck;
    List<Fragment> fragments;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ViewUtils.inject(this);

        //暂时用这个用户id来测试
        SPHelper.setUserId(4271203);

        fragments=new ArrayList<>();
        fragments.add(new SocialFragment());
        fragments.add(new RingFragment());
        fragments.add(new FindFragment());
        fragments.add(new ActionFragment());
        fragments.add(new MineFragment());
        mCheck.check(R.id.main_tab_check1);
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.main_content,fragments.get(0));
        transaction.commit();
        setCheck();
    }
    private void setCheck(){
        mCheck.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
                switch (checkedId){
                    case R.id.main_tab_check1:
                        transaction.replace(R.id.main_content,fragments.get(0));
                        break;
                    case R.id.main_tab_check2:
                        transaction.replace(R.id.main_content,fragments.get(1));
                        break;
                    case R.id.main_tab_check3:
                        transaction.replace(R.id.main_content,fragments.get(2));
                        break;
                    case R.id.main_tab_check4:
                        transaction.replace(R.id.main_content,fragments.get(3));
                        break;
                    case R.id.main_tab_check5:
                        transaction.replace(R.id.main_content,fragments.get(4));
                        break;
                }
                transaction.commit();
            }
        });
    }
}
